package example.thread;

/**
 * Created by lenovo on 2016/11/7 0007.
 * Thread 类并使用 getName() 方法来获取当前线程名称
 */
public class GetThreadName extends Thread {
    public void run() {
        for (int i = 0; i < 10; i++) {
            printMsg();
        }
    }

    private void printMsg() {
        Thread t = Thread.currentThread();
        String name = t.getName();
        System.out.println("name=" + name);
    }

    public static void main(String[] args) {
        GetThreadName tt = new GetThreadName();
        tt.start();
        for (int i = 0; i < 10; i++) {
            tt.printMsg();
        }
    }
}
